//! Tools.

use alloc::alloc::handle_alloc_error;
use core::alloc::Layout;

/// Print log using `libc_print::libc_println!`.
/// Enabled by feature `log`.
#[macro_export]
macro_rules! log_println {
    ($($arg:tt)*) => {
        #[cfg(feature = "log")]
        libc_print::libc_println!($($arg)*);
    };
}

/// Print log before `handle_alloc_error`.
pub fn handle_alloc_error_with_log(layout: Layout, msg: &str) -> ! {
    libc_print::libc_eprintln!("mimalloc error: {}" ,msg);
    handle_alloc_error(layout)
}
